#include <string.h>
#include "../../inc/pseRobotCacheer.h"

int main(void){
    PseRobotCacheer robot;
    unsigned int  cache_size = 500000;
    unsigned int  hash_size = 500000;
    unsigned int  expired_seconds = 1;
    char         *filename = "report.dat";
    char         *cache_name = "ROBOTS Cache";

/*
    if(robot.load_file(filename) == 0){
        printf("loading file is successfully\n");
    }

    return 0;
*/
    FILE *robot_fp = NULL;
    char *robot_str = NULL;
    char  buf[1024];
    robot_fp = fopen("/home/eric/log/aalert_log_tokenize", "r");
    
    robot.set_expired_seconds(expired_seconds);
    if(robot.init(cache_size, hash_size) != true){
        printf("initiaizing is failed\n");
    }    
    
    /* read robots.txt from file */
    const char* robot_filename = "robots.txt";
    /*
    if(robot_fp == NULL){
        printf("could not open file\n");
        exit(1);
    }
    else{
        while((robot_str = fgets(buf, 1024, robot_fp)) != NULL){
            if(robot.robot_cached(robot_str, strlen(robot_str), 
                                  robot_filename) == 0){
                printf("cached robot is successfully\n");
            }            
        }
    }
    */
    /* read robots.txt from string */    
    if(robot_fp == NULL){
        printf("could not open file\n");
        exit(1);
    }
    else{
        while((robot_str = fgets(buf, 1024, robot_fp)) != NULL){
            if(robot.insert(robot_str, strlen(robot_str), NULL, 0) == true){
                //printf("cached dns is successfully\n");
            }            
        }
    }
    /* dump report */
    robot.dump_report(cache_name, filename);

    if(robot.dump_file("hash_data.dat") == true){
        printf("dump file is successfully\n");
    }    
    /* free the robot cache objects */
    if(robot.free_item() == true){
        printf("free the object of robots.txt cache is successfully\n");
    }
    return 0;
}
